<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>发布订阅模式</h1>

<script>
/*
* publish 发布
* subscribe 订阅
* */

    // 中央调度中心
    let sub = {
        list:[],
        // 发布
        publish(){
            this.list.forEach((item=>{
                item()
            }))
        },
        // 订阅
        subscribe(cb){
            this.list.push(cb)
        }
    }
    function testA(){
        console.log('testa')
    }
    function testB(){
        console.log('testb')
    }
    sub.subscribe(testA)
    sub.subscribe(testB)
    console.log(sub.publish())

</script>

</body>
</html>
